package edu.gxmzu.task.controller;

import com.github.pagehelper.PageInfo;
import edu.gxmzu.task.filter.JwtAuthenticationTokenFilter;
import edu.gxmzu.task.models.UserMyMessageModel;
import edu.gxmzu.task.service.UserMyMessageService;
import edu.gxmzu.task.utils.JWTUtil;
import edu.gxmzu.task.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Tag(name = "用户模块", description = "用户相关操作")
public class UserMyMessageController {
    @Resource
    private UserMyMessageService userMyMessageService;

    @Operation(summary = "查询我的消息")
    @GetMapping("/getMyMessage")
    public Result<PageInfo<UserMyMessageModel>> getUserMyInfo(
            @Parameter(description = "当前为第几页") @RequestParam(defaultValue = "1") int pageNum,
            @Parameter(description = "每页显示的数据") @RequestParam(defaultValue = "10") int pageSize,
            @Nullable @Parameter(description = "发件人名字") String appointorName,
            @Nullable @Parameter(description = "开始时间戳")Long startTime,
            @Nullable @Parameter(description = "结束时间戳") Long endTime,
            @Nullable @Parameter(description = "标题") String title,
            HttpServletRequest request){
        String token = request.getHeader(JwtAuthenticationTokenFilter.TOKEN_KEY);
        String userId = JWTUtil.getUserIdFromToken(token);
        PageInfo<UserMyMessageModel> userMyInfo = userMyMessageService.getUserMyMessage(pageNum ,pageSize,userId,appointorName,startTime,endTime,title);
        return Result.ok("200",userMyInfo);
    }
}